<template>
	<el-table
		ref="multipleTable" border
		:data="tableData"
		:default-sort="{ prop: 'name', order: 'descending' }"
		:row-style="{ height: '35px' }"
		:cell-style="{ padding: '0' }"
		size="medium"
		style="width: 100%"
	>
		<el-table-column align="center" label="序号" type="index" width="60"> </el-table-column>
		<el-table-column align="center" property="no" label="物品编号" width="180px" show-overflow-tooltip />
		<el-table-column align="center" property="name" label="物品名称" show-overflow-tooltip />
		<el-table-column align="center" property="source" label="经办人" show-overflow-tooltip />
			<el-table-column align="center" property="extractionPersonName"  label="保管单位" show-overflow-tooltip />
				<el-table-column align="center" property="extractionDateTime"  label="办理时间" show-overflow-tooltip>
					<template #default="scope">{{ dateFormat(scope.row.extractionDateTime) }}</template>
				</el-table-column>
		<el-table-column align="center" property="extractMethod"  label="案卷来源" show-overflow-tooltip />
		<el-table-column
			align="center"
			property="evidencePerson"
			
			:label="outTypeTitle + '数量/总数'"
			show-overflow-tooltip
			width="240px"
			v-if="!showOperation"
		/>
		<el-table-column align="center" width="240px" property="evidencePerson"  :label="outTypeTitle + '数量/总数'" show-overflow-tooltip v-else>
			<template #default="scope">
				<el-input-number readonly v-model="scope.row.quantity" :min="1" :max="scope.row.quantity" style="width: 120px" /> /{{ scope.row.quantity }}
			</template>
		</el-table-column>
		<el-table-column align="center" property="location"  label="位置" show-overflow-tooltip v-if="outType != 6" />
		<el-table-column align="center" label="操作" width="150px" v-if="showOperation">
			<template #default="scope">
				<el-button type="primary" plain size="mini" @click="onEditEvidenceInfo(scope.row)">移除</el-button>
			</template>
		</el-table-column>
	</el-table>
</template>
<script lang="ts">
import { toRefs, reactive } from 'vue';
import { dateFormat } from '/@/common/index';
import { GetCaseBorrowEvdences } from '/@/api/evidence/index';
import { getOutType } from '/@/common/index';
export default {
	name: 'BorrowEvidenceList',
	props: {
		outType: String,
		showOperation: Boolean,
		caseId: Number,
		selectionEvidences: Array,
	},
	setup(props: any) {
		const state = reactive({
			showOperation: props.showOperation,
			outTypeTitle: getOutType(props.outType),
			outType: props.outType,
			tableData: [],
			options: { tqrs: [], tqdws: [] },
		});
		function onEditEvidenceInfo(row: any) {
			const index = state.tableData.findIndex((x: any) => x.id == row.id);
			state.tableData.splice(index, 1);
		}
		function init() {
			if(props.caseId){
				const _status = state.outType == 6 ? 2 : 1;
				GetCaseBorrowEvdences({
					caseid: props.caseId,
					status: _status,
				}).then((res: any) => {
					if (res.success) {
						state.tableData = res.data;
					}
				});
			}
			else if (props.selectionEvidences?.length > 0) {
				state.tableData = props.selectionEvidences;
			} 
		}
		init();
		return {
			dateFormat,
			onEditEvidenceInfo,
			init,
			...toRefs(state),
		};
	},
};
</script>
